@extends('admin.layout')

@section('content')

@section('Dashboard','前台用户管理')
@section('Control','列表')
@section('Home','主页')
@section('Dash','前台用户列表')
<!-- Content Wrapper. Contains page content -->
<!--    <div class="content-wrapper">
         Content Header (Page header) 
        <section class="content-header">
            <h1>
                前台用户管理
                <small>列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
                <li><a href="#">前台用户管理</a></li>
                <li class="active">列表</li>
            </ol>
        </section>-->

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看用户</h3>
                        </div><!-- /.box-header -->
                        
                        <form action="{{ url('/admin/homeuser/index') }}" method='get'>
                           
                    <div class='row'>
                           
                        <div class='col-md-4'>
                             <div class="form-group">
                             <label>
                               <select name="num" aria-controls="example1" class="form-control input-sm">
                                     <option
                                         @if( !empty($request['num'])
                                         && $request['num'] == 10)
                                            selected = 'selected'
                                         @endif
                                         value="10">显示10页</option>
                                     <option
                                         @if(!empty($request['num'])
                                         && $request['num'] == 25)
                                            selected = 'selected'
                                         @endif
                                          value="25">显示25页</option>
                                     <option
                                         @if(!empty($request['num'])
                                         && $request['num'] == 50)
                                            selected = 'selected'
                                         @endif
                                          value="50">显示50页</option>
                                     <option
                                         @if(!empty($request['num'])
                                         && $request['num'] == 100)
                                            selected = 'selected'
                                         @endif
                                          value="100">显示100页</option>
                                 </select>
                             </label>
                             </div>
                        </div>
                           
                            
                            <div class='col-md-4 col-md-offset-4'>
                                <div class="input-group input-group-sm">
                                    <input type="text" name='keywords' value='{{ $request['keywords'] or '' }}' class="form-control">
                                    <span class="input-group-btn">
                                        <button class="btn btn-info btn-flat">搜索</button>
                                    </span>
                             </div>
                            </div>
                        </div>
                        
                        </form>
                        
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>头像</th>
                            <th>手机</th>
                            <th>邮箱</th>
                            <th>黑名单</th>
                        </tr>
                    </thead>
                                
                    <tbody>
                        @foreach($users as $user )
                   
                        <tr>
                            <td class="ids">{{ $user -> id }}</td>
                            <td>{{ $user -> name }}</td>
                            <td>{{ $user -> img }}</td>
                            <td>{{ $user -> phone }}</td>
                            <td>{{ $user -> email }}</td>
                            <td class="status">
                                @if($user -> status == 0)
                                    普通会员
                                @else
                                    恶意会员
                                @endif
                            <td>
                        </tr>
                   @endforeach      
                        
                    </tbody>
                     
                            </table>
                            
                          
                            {!! $users->appends($request)->render() !!}
                            
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->

    <script type="text/javascript">
        window.onload = function()
        {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            
            //发送ajax
             //alert($);
             $('.status').on('click',function(){
//                 alert('11111');
                    //获取id
//                    var id = $(this).parent().children().first().html(;
                    var id = $(this).parent().find('.ids').html();
//                    alert(id);
                    
                    //获取当前对象
                    var r = $(this);
                    
                    $.ajax({
                        url:"{{ url('/admin/homeuser/ajaxUpdate') }}",
                        type:"POST",
                        data:{id:id},
                        success:function($data)
                        {
//                            alert(234567);
                            if($data == 0)
                            {
                               r.html('普通会员');
                            } else if($data == 1)
                            {
                                r.html('恶意会员');
                            } else
                            {
                                alert('修改失败');
                            }
                            
                        },
                        dataType:'json'
                        
                    });
             });
         
        };
    </script>
    
@endsection